package top.bug.blog.controller.backend;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.bug.blog.annotation.Auth;
import top.bug.blog.common.Result;
import top.bug.blog.entity.dto.article.*;
import top.bug.blog.entity.dto.common.BatchRequest;
import top.bug.blog.entity.dto.common.OrderModRequest;
import top.bug.blog.entity.dto.common.SingleRequest;
import top.bug.blog.entity.vo.article.ArticleVO;
import top.bug.blog.service.ArticleService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @author <a href="https://github.com/jiusi66">九思.</a>
 * @email 10837907@qq.com
 * @from <a href="https://www.52bug.top">递归茶馆-www.52bug.top</a>
 * @description 后台-文章模块
 */
@Api(tags = "文章管理模块")
@RestController
@RequestMapping("/articleApi")
@Auth
public class ArticleController {
    @Resource
    private ArticleService articleService;

    @PostMapping("/details")
    @ApiOperation("获取详情")
    public Result<ArticleVO> details(SingleRequest singleRequest) {
        return Result.success(articleService.details(singleRequest));
    }

    @PostMapping("/getList")
    @ApiOperation("获取列表")
    public Result<Page<ArticleVO>> getList(@RequestBody ArticleQueryRequest queryRequest) {
        return Result.success(articleService.getList(queryRequest));
    }

    @PostMapping("/add")
    @ApiOperation("新增文章")
    public Result<Boolean> add(@RequestBody ArticleAddRequest addRequest) {
        return Result.success(articleService.add(addRequest));
    }

    @PostMapping("/edit")
    @ApiOperation("编辑文章")
    public Result<Boolean> edit(@RequestBody ArticleUpdateRequest updateRequest) {
        return Result.success(articleService.edit(updateRequest));
    }

    @PostMapping("/delete")
    @ApiOperation("批量删除")
    public Result<Boolean> delete(@RequestBody BatchRequest batchRequest) {
        return Result.success(articleService.delete(batchRequest));
    }

    @PostMapping("/editOrder")
    @ApiOperation("修改排序")
    public Result<Boolean> editOrder(@RequestBody OrderModRequest orderModRequest) {
        return Result.success(articleService.editOrder(orderModRequest));
    }

    @PostMapping("/updateRecommend")
    @ApiOperation("更新推荐状态")
    public Result<Boolean> updateRecommend(ArticleRecommendRequest recommendRequest) {
        return Result.success(articleService.updateRecommend(recommendRequest));
    }

    @PostMapping("/publish")
    @ApiOperation("发布文章")
    public Result<String> publish(@RequestBody ArticlePublishRequest publishRequest) {
        return Result.success(articleService.publish(publishRequest));
    }

    @PostMapping("/exportMarkdown")
    @ApiOperation("导出markdown")
    public void exportMarkdown(SingleRequest singleRequest, HttpServletResponse response) {
        articleService.exportMarkdown(singleRequest, response);
    }

    @PostMapping("/autoSummary")
    @ApiOperation("AI生成摘要")
    public Result<String> autoSummary(@RequestBody ArticleAutoSummaryRequest autoSummaryRequest) {
        return Result.success(articleService.autoSummary(autoSummaryRequest));
    }

}